package com.nfzm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

//@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedOrigin("http://localhost"); // 允许的源地址，可以根据实际情况调整
        config.addAllowedOrigin("http://178250.xyz");
        config.addAllowedOrigin("http://39.98.118.210");
        //config.addAllowedOrigin("http://127.0.0.1");
        config.addAllowedMethod("*"); // 允许的 HTTP 方法
        config.addAllowedHeader("*"); // 允许的请求头
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
}